package cn.hiapi.admin.api;

import cn.hiapi.admin.query.activity_order.AdminActivityExpandOrderQuery;
import cn.hiapi.admin.vo.activity_order.ActivityVoteOrderVo;
import cn.hiapi.basic.controller.BasicQueryController;
import cn.hiapi.basic.service.BasicService;
import cn.hiapi.interfaces.DispatchContext;
import cn.hiapi.interfaces.user.IUserService;
import cn.hiapi.shopkeeper.entity.order.ActivityVoteOrder;
import cn.hiapi.shopkeeper.service.order.ActivityVoteOrderService;
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author AdinZ
 * @date 2023/2/16 15:36
 */
@RestController
@RequestMapping("/manage/activity-order/vote")
public class AdminActivityVoteOrderController extends BasicQueryController<ActivityVoteOrder, Long, ActivityVoteOrderVo, AdminActivityExpandOrderQuery> {
    protected AdminActivityVoteOrderController(ActivityVoteOrderService basicService, DispatchContext dispatchContext) {
        super(basicService, dispatchContext);
    }

    @Override
    public List<ActivityVoteOrderVo> toListVo(List<ActivityVoteOrder> list, String[] fields) {
        return this.toList(list, fields);
    }

    @Override
    public ActivityVoteOrderVo toData(ActivityVoteOrder data, String[] fields) {
        ActivityVoteOrderVo vo = data.copy(new ActivityVoteOrderVo());
        vo.setUser(this.dispatchContext.getServiceOne(IUserService.class).fieldBase(vo.getUid()));

        if (StringUtils.isNotEmpty(data.getOtherText())) {
            vo.setOther(JSON.parseObject(data.getOtherText()));
        }

        return vo;
    }
}
